package org.apache.commons.httpclient.cookie;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.StringTokenizer;
import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HeaderElement;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.util.ParameterFormatter;
import org.apache.commons.logging.Log;

public class RFC2965Spec extends CookieSpecBase
  implements CookieVersionSupport
{
  private static final Comparator PATH_COMPOARATOR = new CookiePathComparator();
  public static final String SET_COOKIE2_KEY = "set-cookie2";
  private final List attribHandlerList;
  private final Map attribHandlerMap;
  private final ParameterFormatter formatter = new ParameterFormatter();
  private final CookieSpec rfc2109;

  public RFC2965Spec()
  {
    this.formatter.setAlwaysUseQuotes(true);
    this.attribHandlerMap = new HashMap(10);
    this.attribHandlerList = new ArrayList(10);
    this.rfc2109 = new RFC2109Spec();
    registerAttribHandler("path", new Cookie2PathAttributeHandler(null));
    registerAttribHandler("domain", new Cookie2DomainAttributeHandler(null));
    registerAttribHandler("port", new Cookie2PortAttributeHandler(null));
    registerAttribHandler("max-age", new Cookie2MaxageAttributeHandler(null));
    registerAttribHandler("secure", new CookieSecureAttributeHandler(null));
    registerAttribHandler("comment", new CookieCommentAttributeHandler(null));
    registerAttribHandler("commenturl", new CookieCommentUrlAttributeHandler(null));
    registerAttribHandler("discard", new CookieDiscardAttributeHandler(null));
    registerAttribHandler("version", new Cookie2VersionAttributeHandler(null));
  }

  private String createPortAttribute(int[] paramArrayOfInt)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    int i = 0;
    int j = paramArrayOfInt.length;
    while (i < j)
    {
      if (i > 0)
        localStringBuffer.append(",");
      localStringBuffer.append(paramArrayOfInt[i]);
      ++i;
    }
    return localStringBuffer.toString();
  }

  private void doFormatCookie2(Cookie2 paramCookie2, StringBuffer paramStringBuffer)
  {
    String str1 = paramCookie2.getName();
    String str2 = paramCookie2.getValue();
    if (str2 == null)
      str2 = "";
    this.formatter.format(paramStringBuffer, new NameValuePair(str1, str2));
    if ((paramCookie2.getDomain() != null) && (paramCookie2.isDomainAttributeSpecified()))
    {
      paramStringBuffer.append("; ");
      this.formatter.format(paramStringBuffer, new NameValuePair("$Domain", paramCookie2.getDomain()));
    }
    if ((paramCookie2.getPath() != null) && (paramCookie2.isPathAttributeSpecified()))
    {
      paramStringBuffer.append("; ");
      this.formatter.format(paramStringBuffer, new NameValuePair("$Path", paramCookie2.getPath()));
    }
    if (!(paramCookie2.isPortAttributeSpecified()))
      return;
    String str3 = "";
    if (!(paramCookie2.isPortAttributeBlank()))
      str3 = createPortAttribute(paramCookie2.getPorts());
    paramStringBuffer.append("; ");
    this.formatter.format(paramStringBuffer, new NameValuePair("$Port", str3));
  }

  private static String getEffectiveHost(String paramString)
  {
    String str = paramString.toLowerCase();
    if (paramString.indexOf(46) < 0)
      str = str + ".local";
    return str;
  }

  private int[] parsePortAttribute(String paramString)
    throws MalformedCookieException
  {
    StringTokenizer localStringTokenizer = new StringTokenizer(paramString, ",");
    int[] arrayOfInt = new int[localStringTokenizer.countTokens()];
    for (int i = 0; ; ++i)
      try
      {
        if (!(localStringTokenizer.hasMoreTokens()))
          break label98;
        arrayOfInt[i] = Integer.parseInt(localStringTokenizer.nextToken().trim());
        if (arrayOfInt[i] < 0)
          throw new MalformedCookieException("Invalid Port attribute.");
      }
      catch (NumberFormatException localNumberFormatException)
      {
        throw new MalformedCookieException("Invalid Port attribute: " + localNumberFormatException.getMessage());
      }
    label98: return arrayOfInt;
  }

  private boolean portMatch(int paramInt, int[] paramArrayOfInt)
  {
    int i = 0;
    int j = 0;
    int k = paramArrayOfInt.length;
    while (true)
    {
      if (j < k)
      {
        if (paramInt != paramArrayOfInt[j])
          break label28;
        i = 1;
      }
      return i;
      label28: ++j;
    }
  }

  public boolean domainMatch(String paramString1, String paramString2)
  {
    if ((paramString1.equals(paramString2)) || ((paramString2.startsWith(".")) && (paramString1.endsWith(paramString2))));
    for (int i = 1; ; i = 0)
      return i;
  }

  protected CookieAttributeHandler findAttribHandler(String paramString)
  {
    return ((CookieAttributeHandler)this.attribHandlerMap.get(paramString));
  }

  public String formatCookie(Cookie paramCookie)
  {
    LOG.trace("enter RFC2965Spec.formatCookie(Cookie)");
    if (paramCookie == null)
      throw new IllegalArgumentException("Cookie may not be null");
    StringBuffer localStringBuffer;
    if (paramCookie instanceof Cookie2)
    {
      Cookie2 localCookie2 = (Cookie2)paramCookie;
      int i = localCookie2.getVersion();
      localStringBuffer = new StringBuffer();
      this.formatter.format(localStringBuffer, new NameValuePair("$Version", Integer.toString(i)));
      localStringBuffer.append("; ");
      doFormatCookie2(localCookie2, localStringBuffer);
    }
    for (String str = localStringBuffer.toString(); ; str = this.rfc2109.formatCookie(paramCookie))
      return str;
  }

  public String formatCookies(Cookie[] paramArrayOfCookie)
  {
    LOG.trace("enter RFC2965Spec.formatCookieHeader(Cookie[])");
    if (paramArrayOfCookie == null)
      throw new IllegalArgumentException("Cookies may not be null");
    int i = 0;
    int j = -1;
    int k = 0;
    label34: Cookie localCookie;
    if (k < paramArrayOfCookie.length)
    {
      localCookie = paramArrayOfCookie[k];
      if (localCookie instanceof Cookie2)
        break label87;
      i = 1;
    }
    if (j < 0)
      j = 0;
    if ((i != 0) || (j < 1));
    label87: StringBuffer localStringBuffer;
    for (String str = this.rfc2109.formatCookies(paramArrayOfCookie); ; str = localStringBuffer.toString())
    {
      return str;
      if (localCookie.getVersion() > j)
        j = localCookie.getVersion();
      ++k;
      break label34:
      Arrays.sort(paramArrayOfCookie, PATH_COMPOARATOR);
      localStringBuffer = new StringBuffer();
      this.formatter.format(localStringBuffer, new NameValuePair("$Version", Integer.toString(j)));
      for (int l = 0; l < paramArrayOfCookie.length; ++l)
      {
        localStringBuffer.append("; ");
        doFormatCookie2((Cookie2)paramArrayOfCookie[l], localStringBuffer);
      }
    }
  }

  protected CookieAttributeHandler getAttribHandler(String paramString)
  {
    CookieAttributeHandler localCookieAttributeHandler = findAttribHandler(paramString);
    if (localCookieAttributeHandler == null)
      throw new IllegalStateException("Handler not registered for " + paramString + " attribute.");
    return localCookieAttributeHandler;
  }

  protected Iterator getAttribHandlerIterator()
  {
    return this.attribHandlerList.iterator();
  }

  public int getVersion()
  {
    return 1;
  }

  public Header getVersionHeader()
  {
    ParameterFormatter localParameterFormatter = new ParameterFormatter();
    StringBuffer localStringBuffer = new StringBuffer();
    localParameterFormatter.format(localStringBuffer, new NameValuePair("$Version", Integer.toString(getVersion())));
    return new Header("Cookie2", localStringBuffer.toString(), true);
  }

  public boolean match(String paramString1, int paramInt, String paramString2, boolean paramBoolean, Cookie paramCookie)
  {
    LOG.trace("enter RFC2965.match(String, int, String, boolean, Cookie");
    if (paramCookie == null)
      throw new IllegalArgumentException("Cookie may not be null");
    if (paramCookie instanceof Cookie2)
      if ((!(paramCookie.isPersistent())) || (!(paramCookie.isExpired())));
    for (boolean bool = false; ; bool = this.rfc2109.match(paramString1, paramInt, paramString2, paramBoolean, paramCookie))
      while (true)
      {
        return bool;
        CookieOrigin localCookieOrigin = new CookieOrigin(getEffectiveHost(paramString1), paramInt, paramString2, paramBoolean);
        Iterator localIterator = getAttribHandlerIterator();
        do
          if (!(localIterator.hasNext()))
            break label118;
        while (((CookieAttributeHandler)localIterator.next()).match(paramCookie, localCookieOrigin));
        bool = false;
        continue;
        label118: bool = true;
      }
  }

  public Cookie[] parse(String paramString1, int paramInt, String paramString2, boolean paramBoolean, String paramString3)
    throws MalformedCookieException
  {
    LOG.trace("enter RFC2965Spec.parse(String, int, String, boolean, String)");
    if (paramString1 == null)
      throw new IllegalArgumentException("Host of origin may not be null");
    if (paramString1.trim().equals(""))
      throw new IllegalArgumentException("Host of origin may not be blank");
    if (paramInt < 0)
      throw new IllegalArgumentException("Invalid port: " + paramInt);
    if (paramString2 == null)
      throw new IllegalArgumentException("Path of origin may not be null.");
    if (paramString3 == null)
      throw new IllegalArgumentException("Header may not be null.");
    if (paramString2.trim().equals(""))
      paramString2 = "/";
    String str1 = getEffectiveHost(paramString1);
    HeaderElement[] arrayOfHeaderElement = HeaderElement.parseElements(paramString3.toCharArray());
    LinkedList localLinkedList = new LinkedList();
    for (int i = 0; ; ++i)
    {
      int j = arrayOfHeaderElement.length;
      if (i >= j)
        break;
      HeaderElement localHeaderElement = arrayOfHeaderElement[i];
      Cookie2 localCookie2;
      HashMap localHashMap;
      try
      {
        String str2 = localHeaderElement.getName();
        String str3 = localHeaderElement.getValue();
        int[] arrayOfInt = new int[1];
        arrayOfInt[0] = paramInt;
        localCookie2 = new Cookie2(str1, str2, str3, paramString2, null, false, arrayOfInt);
        NameValuePair[] arrayOfNameValuePair = localHeaderElement.getParameters();
        if (arrayOfNameValuePair == null)
          break label352;
        localHashMap = new HashMap(arrayOfNameValuePair.length);
        int k = arrayOfNameValuePair.length - 1;
        if (k < 0)
          break label301;
        NameValuePair localNameValuePair = arrayOfNameValuePair[k];
        localHashMap.put(localNameValuePair.getName().toLowerCase(), localNameValuePair);
        --k;
      }
      catch (IllegalArgumentException localIllegalArgumentException)
      {
        throw new MalformedCookieException(localIllegalArgumentException.getMessage());
      }
      label301: Iterator localIterator = localHashMap.entrySet().iterator();
      while (localIterator.hasNext())
        parseAttribute((NameValuePair)((Map.Entry)localIterator.next()).getValue(), localCookie2);
      label352: localLinkedList.add(localCookie2);
    }
    return ((Cookie[])(Cookie[])localLinkedList.toArray(new Cookie[localLinkedList.size()]));
  }

  public Cookie[] parse(String paramString1, int paramInt, String paramString2, boolean paramBoolean, Header paramHeader)
    throws MalformedCookieException
  {
    LOG.trace("enter RFC2965.parse(String, int, String, boolean, Header)");
    if (paramHeader == null)
      throw new IllegalArgumentException("Header may not be null.");
    if (paramHeader.getName() == null)
      throw new IllegalArgumentException("Header name may not be null.");
    if (paramHeader.getName().equalsIgnoreCase("set-cookie2"));
    for (Cookie[] arrayOfCookie = parse(paramString1, paramInt, paramString2, paramBoolean, paramHeader.getValue()); ; arrayOfCookie = this.rfc2109.parse(paramString1, paramInt, paramString2, paramBoolean, paramHeader.getValue()))
    {
      return arrayOfCookie;
      if (!(paramHeader.getName().equalsIgnoreCase("set-cookie")))
        break;
    }
    throw new MalformedCookieException("Header name is not valid. RFC 2965 supports \"set-cookie\" and \"set-cookie2\" headers.");
  }

  public void parseAttribute(NameValuePair paramNameValuePair, Cookie paramCookie)
    throws MalformedCookieException
  {
    if (paramNameValuePair == null)
      throw new IllegalArgumentException("Attribute may not be null.");
    if (paramNameValuePair.getName() == null)
      throw new IllegalArgumentException("Attribute Name may not be null.");
    if (paramCookie == null)
      throw new IllegalArgumentException("Cookie may not be null.");
    String str1 = paramNameValuePair.getName().toLowerCase();
    String str2 = paramNameValuePair.getValue();
    CookieAttributeHandler localCookieAttributeHandler = findAttribHandler(str1);
    if (localCookieAttributeHandler == null)
      if (LOG.isDebugEnabled())
        LOG.debug("Unrecognized cookie attribute: " + paramNameValuePair.toString());
    while (true)
    {
      return;
      localCookieAttributeHandler.parse(paramCookie, str2);
    }
  }

  protected void registerAttribHandler(String paramString, CookieAttributeHandler paramCookieAttributeHandler)
  {
    if (paramString == null)
      throw new IllegalArgumentException("Attribute name may not be null");
    if (paramCookieAttributeHandler == null)
      throw new IllegalArgumentException("Attribute handler may not be null");
    if (!(this.attribHandlerList.contains(paramCookieAttributeHandler)))
      this.attribHandlerList.add(paramCookieAttributeHandler);
    this.attribHandlerMap.put(paramString, paramCookieAttributeHandler);
  }

  public void validate(String paramString1, int paramInt, String paramString2, boolean paramBoolean, Cookie paramCookie)
    throws MalformedCookieException
  {
    LOG.trace("enter RFC2965Spec.validate(String, int, String, boolean, Cookie)");
    if (paramCookie instanceof Cookie2)
    {
      if (paramCookie.getName().indexOf(32) != -1)
        throw new MalformedCookieException("Cookie name may not contain blanks");
      if (paramCookie.getName().startsWith("$"))
        throw new MalformedCookieException("Cookie name may not start with $");
      CookieOrigin localCookieOrigin = new CookieOrigin(getEffectiveHost(paramString1), paramInt, paramString2, paramBoolean);
      Iterator localIterator = getAttribHandlerIterator();
      while (true)
      {
        if (!(localIterator.hasNext()))
          return;
        ((CookieAttributeHandler)localIterator.next()).validate(paramCookie, localCookieOrigin);
      }
    }
    this.rfc2109.validate(paramString1, paramInt, paramString2, paramBoolean, paramCookie);
  }

  private class Cookie2DomainAttributeHandler
    implements CookieAttributeHandler
  {
    private final RFC2965Spec this$0;

    private Cookie2DomainAttributeHandler()
    {
      this.this$0 = this$1;
    }

    Cookie2DomainAttributeHandler(RFC2965Spec.1 param1)
    {
      this(this$1);
    }

    public boolean match(Cookie paramCookie, CookieOrigin paramCookieOrigin)
    {
      if (paramCookie == null)
        throw new IllegalArgumentException("Cookie may not be null");
      if (paramCookieOrigin == null)
        throw new IllegalArgumentException("Cookie origin may not be null");
      String str1 = paramCookieOrigin.getHost().toLowerCase();
      String str2 = paramCookie.getDomain();
      if (!(this.this$0.domainMatch(str1, str2)));
      for (int i = 0; ; i = 1)
        while (true)
        {
          return i;
          if (str1.substring(0, str1.length() - str2.length()).indexOf(46) == -1)
            break;
          i = 0;
        }
    }

    public void parse(Cookie paramCookie, String paramString)
      throws MalformedCookieException
    {
      if (paramCookie == null)
        throw new IllegalArgumentException("Cookie may not be null");
      if (paramString == null)
        throw new MalformedCookieException("Missing value for domain attribute");
      if (paramString.trim().equals(""))
        throw new MalformedCookieException("Blank value for domain attribute");
      String str = paramString.toLowerCase();
      if (!(str.startsWith(".")))
        str = "." + str;
      paramCookie.setDomain(str);
      paramCookie.setDomainAttributeSpecified(true);
    }

    public void validate(Cookie paramCookie, CookieOrigin paramCookieOrigin)
      throws MalformedCookieException
    {
      if (paramCookie == null)
        throw new IllegalArgumentException("Cookie may not be null");
      if (paramCookieOrigin == null)
        throw new IllegalArgumentException("Cookie origin may not be null");
      String str1 = paramCookieOrigin.getHost().toLowerCase();
      if (paramCookie.getDomain() == null)
        throw new MalformedCookieException("Invalid cookie state: domain not specified");
      String str2 = paramCookie.getDomain().toLowerCase();
      if (paramCookie.isDomainAttributeSpecified())
      {
        if (!(str2.startsWith(".")))
          throw new MalformedCookieException("Domain attribute \"" + paramCookie.getDomain() + "\" violates RFC 2109: domain must start with a dot");
        int i = str2.indexOf(46, 1);
        if ((((i < 0) || (i == str2.length() - 1))) && (!(str2.equals(".local"))))
          throw new MalformedCookieException("Domain attribute \"" + paramCookie.getDomain() + "\" violates RFC 2965: the value contains no embedded dots " + "and the value is not .local");
        if (!(this.this$0.domainMatch(str1, str2)))
          throw new MalformedCookieException("Domain attribute \"" + paramCookie.getDomain() + "\" violates RFC 2965: effective host name does not " + "domain-match domain attribute.");
        if (str1.substring(0, str1.length() - str2.length()).indexOf(46) == -1)
          return;
        throw new MalformedCookieException("Domain attribute \"" + paramCookie.getDomain() + "\" violates RFC 2965: " + "effective host minus domain may not contain any dots");
      }
      if (paramCookie.getDomain().equals(str1))
        return;
      throw new MalformedCookieException("Illegal domain attribute: \"" + paramCookie.getDomain() + "\"." + "Domain of origin: \"" + str1 + "\"");
    }
  }

  private class Cookie2MaxageAttributeHandler
    implements CookieAttributeHandler
  {
    private final RFC2965Spec this$0;

    private Cookie2MaxageAttributeHandler()
    {
      this.this$0 = this$1;
    }

    Cookie2MaxageAttributeHandler(RFC2965Spec.1 param1)
    {
      this(this$1);
    }

    public boolean match(Cookie paramCookie, CookieOrigin paramCookieOrigin)
    {
      return true;
    }

    public void parse(Cookie paramCookie, String paramString)
      throws MalformedCookieException
    {
      if (paramCookie == null)
        throw new IllegalArgumentException("Cookie may not be null");
      if (paramString == null)
        throw new MalformedCookieException("Missing value for max-age attribute");
      int i;
      try
      {
        int j = Integer.parseInt(paramString);
        i = j;
        label38: if (i >= 0)
          break label61;
        label61: throw new MalformedCookieException("Invalid max-age attribute.");
      }
      catch (NumberFormatException localNumberFormatException)
      {
        i = -1;
        break label38:
        paramCookie.setExpiryDate(new Date(System.currentTimeMillis() + 1000L * i));
      }
    }

    public void validate(Cookie paramCookie, CookieOrigin paramCookieOrigin)
    {
    }
  }

  private class Cookie2PathAttributeHandler
    implements CookieAttributeHandler
  {
    private final RFC2965Spec this$0;

    private Cookie2PathAttributeHandler()
    {
      this.this$0 = this$1;
    }

    Cookie2PathAttributeHandler(RFC2965Spec.1 param1)
    {
      this(this$1);
    }

    public boolean match(Cookie paramCookie, CookieOrigin paramCookieOrigin)
    {
      if (paramCookie == null)
        throw new IllegalArgumentException("Cookie may not be null");
      if (paramCookieOrigin == null)
        throw new IllegalArgumentException("Cookie origin may not be null");
      String str = paramCookieOrigin.getPath();
      if (paramCookie.getPath() == null)
        CookieSpecBase.LOG.warn("Invalid cookie state: path attribute is null.");
      for (int i = 0; ; i = 1)
        while (true)
        {
          return i;
          if (str.trim().equals(""))
            str = "/";
          if (this.this$0.pathMatch(str, paramCookie.getPath()))
            break;
          i = 0;
        }
    }

    public void parse(Cookie paramCookie, String paramString)
      throws MalformedCookieException
    {
      if (paramCookie == null)
        throw new IllegalArgumentException("Cookie may not be null");
      if (paramString == null)
        throw new MalformedCookieException("Missing value for path attribute");
      if (paramString.trim().equals(""))
        throw new MalformedCookieException("Blank value for path attribute");
      paramCookie.setPath(paramString);
      paramCookie.setPathAttributeSpecified(true);
    }

    public void validate(Cookie paramCookie, CookieOrigin paramCookieOrigin)
      throws MalformedCookieException
    {
      if (paramCookie == null)
        throw new IllegalArgumentException("Cookie may not be null");
      if (paramCookieOrigin == null)
        throw new IllegalArgumentException("Cookie origin may not be null");
      String str = paramCookieOrigin.getPath();
      if (str == null)
        throw new IllegalArgumentException("Path of origin host may not be null.");
      if (paramCookie.getPath() == null)
        throw new MalformedCookieException("Invalid cookie state: path attribute is null.");
      if (str.trim().equals(""))
        str = "/";
      if (this.this$0.pathMatch(str, paramCookie.getPath()))
        return;
      throw new MalformedCookieException("Illegal path attribute \"" + paramCookie.getPath() + "\". Path of origin: \"" + str + "\"");
    }
  }

  private class Cookie2PortAttributeHandler
    implements CookieAttributeHandler
  {
    private final RFC2965Spec this$0;

    private Cookie2PortAttributeHandler()
    {
      this.this$0 = this$1;
    }

    Cookie2PortAttributeHandler(RFC2965Spec.1 param1)
    {
      this(this$1);
    }

    public boolean match(Cookie paramCookie, CookieOrigin paramCookieOrigin)
    {
      if (paramCookie == null)
        throw new IllegalArgumentException("Cookie may not be null");
      if (paramCookieOrigin == null)
        throw new IllegalArgumentException("Cookie origin may not be null");
      Cookie2 localCookie2;
      int j;
      if (paramCookie instanceof Cookie2)
      {
        localCookie2 = (Cookie2)paramCookie;
        j = paramCookieOrigin.getPort();
        if (localCookie2.isPortAttributeSpecified())
          if (localCookie2.getPorts() == null)
            CookieSpecBase.LOG.warn("Invalid cookie state: port not specified");
      }
      for (int i = 0; ; i = 0)
        while (true)
        {
          return i;
          if (this.this$0.portMatch(j, localCookie2.getPorts()) == 0)
            i = 0;
          i = 1;
        }
    }

    public void parse(Cookie paramCookie, String paramString)
      throws MalformedCookieException
    {
      if (paramCookie == null)
        throw new IllegalArgumentException("Cookie may not be null");
      Cookie2 localCookie2;
      if (paramCookie instanceof Cookie2)
      {
        localCookie2 = (Cookie2)paramCookie;
        if ((paramString != null) && (!(paramString.trim().equals(""))))
          break label53;
        localCookie2.setPortAttributeBlank(true);
      }
      while (true)
      {
        localCookie2.setPortAttributeSpecified(true);
        return;
        label53: localCookie2.setPorts(this.this$0.parsePortAttribute(paramString));
      }
    }

    public void validate(Cookie paramCookie, CookieOrigin paramCookieOrigin)
      throws MalformedCookieException
    {
      if (paramCookie == null)
        throw new IllegalArgumentException("Cookie may not be null");
      if (paramCookieOrigin == null)
        throw new IllegalArgumentException("Cookie origin may not be null");
      if (!(paramCookie instanceof Cookie2))
        return;
      Cookie2 localCookie2 = (Cookie2)paramCookie;
      int i = paramCookieOrigin.getPort();
      if ((!(localCookie2.isPortAttributeSpecified())) || (this.this$0.portMatch(i, localCookie2.getPorts()) != 0))
        return;
      throw new MalformedCookieException("Port attribute violates RFC 2965: Request port not found in cookie's port list.");
    }
  }

  private class Cookie2VersionAttributeHandler
    implements CookieAttributeHandler
  {
    private final RFC2965Spec this$0;

    private Cookie2VersionAttributeHandler()
    {
      this.this$0 = this$1;
    }

    Cookie2VersionAttributeHandler(RFC2965Spec.1 param1)
    {
      this(this$1);
    }

    public boolean match(Cookie paramCookie, CookieOrigin paramCookieOrigin)
    {
      return true;
    }

    public void parse(Cookie paramCookie, String paramString)
      throws MalformedCookieException
    {
      if (paramCookie == null)
        throw new IllegalArgumentException("Cookie may not be null");
      if (!(paramCookie instanceof Cookie2))
        return;
      Cookie2 localCookie2 = (Cookie2)paramCookie;
      if (paramString == null)
        throw new MalformedCookieException("Missing value for version attribute");
      int i;
      try
      {
        int j = Integer.parseInt(paramString);
        i = j;
        label50: if (i >= 0)
          break label74;
        label74: throw new MalformedCookieException("Invalid cookie version.");
      }
      catch (NumberFormatException localNumberFormatException)
      {
        i = -1;
        break label50:
        localCookie2.setVersion(i);
        localCookie2.setVersionAttributeSpecified(true);
      }
    }

    public void validate(Cookie paramCookie, CookieOrigin paramCookieOrigin)
      throws MalformedCookieException
    {
      if (paramCookie == null)
        throw new IllegalArgumentException("Cookie may not be null");
      if ((!(paramCookie instanceof Cookie2)) || (((Cookie2)paramCookie).isVersionAttributeSpecified()))
        return;
      throw new MalformedCookieException("Violates RFC 2965. Version attribute is required.");
    }
  }

  private class CookieCommentAttributeHandler
    implements CookieAttributeHandler
  {
    private final RFC2965Spec this$0;

    private CookieCommentAttributeHandler()
    {
      this.this$0 = this$1;
    }

    CookieCommentAttributeHandler(RFC2965Spec.1 param1)
    {
      this(this$1);
    }

    public boolean match(Cookie paramCookie, CookieOrigin paramCookieOrigin)
    {
      return true;
    }

    public void parse(Cookie paramCookie, String paramString)
      throws MalformedCookieException
    {
      paramCookie.setComment(paramString);
    }

    public void validate(Cookie paramCookie, CookieOrigin paramCookieOrigin)
      throws MalformedCookieException
    {
    }
  }

  private class CookieCommentUrlAttributeHandler
    implements CookieAttributeHandler
  {
    private final RFC2965Spec this$0;

    private CookieCommentUrlAttributeHandler()
    {
      this.this$0 = this$1;
    }

    CookieCommentUrlAttributeHandler(RFC2965Spec.1 param1)
    {
      this(this$1);
    }

    public boolean match(Cookie paramCookie, CookieOrigin paramCookieOrigin)
    {
      return true;
    }

    public void parse(Cookie paramCookie, String paramString)
      throws MalformedCookieException
    {
      if (!(paramCookie instanceof Cookie2))
        return;
      ((Cookie2)paramCookie).setCommentURL(paramString);
    }

    public void validate(Cookie paramCookie, CookieOrigin paramCookieOrigin)
      throws MalformedCookieException
    {
    }
  }

  private class CookieDiscardAttributeHandler
    implements CookieAttributeHandler
  {
    private final RFC2965Spec this$0;

    private CookieDiscardAttributeHandler()
    {
      this.this$0 = this$1;
    }

    CookieDiscardAttributeHandler(RFC2965Spec.1 param1)
    {
      this(this$1);
    }

    public boolean match(Cookie paramCookie, CookieOrigin paramCookieOrigin)
    {
      return true;
    }

    public void parse(Cookie paramCookie, String paramString)
      throws MalformedCookieException
    {
      if (!(paramCookie instanceof Cookie2))
        return;
      ((Cookie2)paramCookie).setDiscard(true);
    }

    public void validate(Cookie paramCookie, CookieOrigin paramCookieOrigin)
      throws MalformedCookieException
    {
    }
  }

  private class CookieSecureAttributeHandler
    implements CookieAttributeHandler
  {
    private final RFC2965Spec this$0;

    private CookieSecureAttributeHandler()
    {
      this.this$0 = this$1;
    }

    CookieSecureAttributeHandler(RFC2965Spec.1 param1)
    {
      this(this$1);
    }

    public boolean match(Cookie paramCookie, CookieOrigin paramCookieOrigin)
    {
      if (paramCookie == null)
        throw new IllegalArgumentException("Cookie may not be null");
      if (paramCookieOrigin == null)
        throw new IllegalArgumentException("Cookie origin may not be null");
      if (paramCookie.getSecure() == paramCookieOrigin.isSecure());
      for (int i = 1; ; i = 0)
        return i;
    }

    public void parse(Cookie paramCookie, String paramString)
      throws MalformedCookieException
    {
      paramCookie.setSecure(true);
    }

    public void validate(Cookie paramCookie, CookieOrigin paramCookieOrigin)
      throws MalformedCookieException
    {
    }
  }
}

/* Location:           E:\Desktop\Android\wordstd\classes_dex2jar.jar
 * Qualified Name:     org.apache.commons.httpclient.cookie.RFC2965Spec
 * JD-Core Version:    0.5.3
 */